package com.xiexuan.InetAdress;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;

public class InetAdressDemo {
	/**
	 * @param args
	 * @throws MalformedURLException
	 * @throws UnknownHostException
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		try {
			InetAddress ip = InetAddress.getByName("WindFlowers");
			System.out.println(ip);
			System.out.println(ip.isReachable(1500));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		URL url = new URL(
				"http://sc1.hao123img.com/res/r/image/2017-10-11/0ba50ace32b7100193c4d200a056a312.jpg");
		URLConnection urlconnection = url.openConnection();
		InputStream in = urlconnection.getInputStream();
		File file = new File("D:/3DMGAME/test/xxx.jpg");
		FileOutputStream fos = new FileOutputStream(file, true);
		file.createNewFile();
		byte[] buffer = new byte[100];
		int len = in.read(buffer);
		while (len != -1) {
			fos.write(buffer, 0, len);
			System.out.println(new String(buffer));
			len = in.read(buffer);
		}
		fos.close();
		in.close();

	}
}
